from AbstractClass.AbstractGetter import AbstractTimer
import datetime

class Timer(AbstractTimer):
    def __init__(self):
        super().__init__()

    def get_data(self, data, extra=None):
        # 解析输入参数
        xqm = data.get("xqm", 3)
        # 获取当前年份
        now = datetime.datetime.now()
        year = now.year

        # 计算开学日期
        if xqm == 3:
            # 9月2日
            semester_start = datetime.datetime(year, 9, 2)
        else:
            # 2月17日
            semester_start = datetime.datetime(year, 2, 17)

        # 转换为时间戳（毫秒级）
        timestamp = int(semester_start.timestamp() * 1000)
        print(f"Generated timestamp: {timestamp}")

        # 构建返回配置
        return {
            "totalWeek": 20 if xqm == 3 else 19,
            "startSemester": str(timestamp),
            "startWithSunday": False,
            "showWeekend": True,
            "forenoon": 4,
            "afternoon": 4,
            "night": 3,
            "sections": [
                {"section": 1, "startTime": "08:00", "endTime": "08:45"},
                {"section": 2, "startTime": "08:55", "endTime": "09:40"},
                {"section": 3, "startTime": "10:10", "endTime": "10:55"},
                {"section": 4, "startTime": "11:05", "endTime": "11:50"},
                {"section": 5, "startTime": "13:40", "endTime": "14:25"},
                {"section": 6, "startTime": "14:35", "endTime": "15:20"},
                {"section": 7, "startTime": "15:40", "endTime": "16:25"},
                {"section": 8, "startTime": "16:35", "endTime": "17:20"},
                {"section": 9, "startTime": "18:30", "endTime": "19:15"},
                {"section": 10, "startTime": "19:25", "endTime": "20:10"},
                {"section": 11, "startTime": "20:20", "endTime": "21:05"}
            ]
        }